home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / extras / Direct3D / Tools / Maya40 / mydt.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  5.0 KB  |  283 lines

  1. #ifndef MyDt_h
  2. #define MyDt_h
  3.  
  4.  
  5. #include <MDt.h>    // Dt API
  6. #include <maya/MTransformationMatrix.h>
  7.  
  8. struct SRep 
  9. {
  10.     UINT m_iUV;        // index into lump of texture coordinates 
  11.     UINT m_iNorm;    // index into lump of normals
  12.     UINT m_iNext;    // next repetition
  13.     UINT m_iFirst;    // can also be thought of as "index into lump of vertices";
  14.  
  15.     // IMPORTANT: the following members are only valid in the instances corresponding to the first rep's.
  16.     UINT m_nReps;                    
  17. };
  18.  
  19.  
  20. struct SFace 
  21. {
  22.     SFace();
  23.    ~SFace();
  24.  
  25.     UINT m_nIndices;        // number of vertices in this face
  26.     UINT* m_aIndices;
  27.     long m_iGroup;            // material group
  28. };
  29.  
  30.  
  31.  
  32. struct SGroup 
  33. {
  34.     char* m_szName;            // material name
  35.     char* m_szTextureFile;    // texture file name
  36.     float m_fDiffuseRed;    // diffuse components    
  37.     float m_fDiffuseGreen;    
  38.     float m_fDiffuseBlue;        
  39.     float m_fSpecularRed;    // specular components    
  40.     float m_fSpecularGreen;    
  41.     float m_fSpecularBlue;        
  42.     float m_fEmissiveRed;    // emissive components    
  43.     float m_fEmissiveGreen;    
  44.     float m_fEmissiveBlue;        
  45.     float m_fShininess;        // specular power
  46.     float m_fTransparency;    // transparency
  47. };
  48.  
  49.  
  50. struct SBone 
  51. {
  52.     SBone();
  53.    ~SBone();
  54.  
  55.     char* m_szName;                // bone name
  56.     UINT m_nReps;                // number of reps influenced
  57.     UINT m_nWeights;            // number of points influenced
  58.     float* m_afWeights;
  59.     UINT* m_aiPoints;
  60.     float m_aafOffset[4][4];    // inverse of bone's world coordinate transform at the time of binding
  61. };
  62.  
  63.  
  64. struct SMesh 
  65. {
  66.     SMesh();
  67.    ~SMesh();
  68.  
  69.     enum ShapeType
  70.     {
  71.         UNKNOWN,
  72.         POLY_MESH,
  73.         PATCH_MESH,
  74.         BONE
  75.     };
  76.  
  77.     ShapeType m_kType;
  78.     // control point info
  79.     UINT m_nReps;
  80.     SRep* m_aReps;
  81.     UINT m_nPoints;
  82.     DtVec3f* m_aPoints;        // lump of vertices
  83.     UINT m_nNormals;
  84.     DtVec3f* m_aNormals;    // lump of normals
  85.     UINT m_nUVs;
  86.     DtVec2f* m_aUVs;        // lump of texture coords
  87.     UINT m_nVertexColors;
  88.     DtRGBA* m_aVertexColors;// lump of vertex colors
  89.     // face info
  90.     UINT m_nFaces;
  91.     SFace* m_aFaces;
  92.     UINT m_nFaceIndices;    // total number of face indices (over all faces).
  93.     // material info
  94.     UINT m_nGroups;
  95.     SGroup* m_aGroups;        // material groups
  96.     // skinning info
  97.     UINT m_nBones;
  98.     SBone* m_aBones;
  99.     UINT m_nMaxBonesPerPoint;
  100.     UINT m_nMaxBonesPerFace;
  101. };
  102.  
  103.  
  104. struct SKey 
  105. {
  106.     UINT m_iFrame;
  107.     float m_afPosition[3];        // translation
  108.     float m_afScale[3];            // scale
  109.     float m_afQuaternion[4];    // quaternion rotation
  110.     float m_afRotation[3];        // euler angles    - NOT USED
  111. };
  112.  
  113.  
  114. struct SAnim 
  115. {
  116.     SAnim();
  117.     ~SAnim();
  118.  
  119.     char* m_szName;
  120.     UINT m_nKeys;
  121.     SKey* m_aKeys;
  122. };
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. typedef enum { FLOAT_ARRAY, STRING, CHAR_ARRAY } ArrayType_t;
  133.  
  134. class CArrayTable
  135. {
  136. private:
  137.     char**    m_aacCharTable;
  138.     UINT    m_uCharTableSize;
  139.     UINT    m_uCharTableMax;
  140.  
  141.     float**    m_aafFloatTable;
  142.     UINT    m_uFloatTableSize;
  143.     UINT    m_uFloatTableMax;
  144.  
  145. public:
  146.     CArrayTable() {};
  147.     ~CArrayTable() {};
  148.  
  149.     HRESULT Initialize();
  150.     HRESULT Add(ArrayType_t, void*);
  151.     HRESULT CleanUp();
  152. };
  153.  
  154.  
  155. inline HRESULT CArrayTable::Initialize()
  156. {
  157.     m_uCharTableSize = 0;
  158.     m_uCharTableMax  = 64;
  159.  
  160.     m_uFloatTableSize = 0;
  161.     m_uFloatTableMax  = 64;
  162.  
  163.     m_aacCharTable = NULL;
  164.     m_aacCharTable = new char*[m_uCharTableMax];
  165.     if (m_aacCharTable == NULL)
  166.         return E_OUTOFMEMORY;
  167.  
  168.     m_aafFloatTable = NULL;
  169.     m_aafFloatTable = new float*[m_uFloatTableMax];
  170.     if (m_aafFloatTable == NULL)
  171.         return E_OUTOFMEMORY;
  172.  
  173.     return S_OK;
  174. }
  175.  
  176. inline HRESULT CArrayTable::CleanUp()
  177. {
  178.     UINT i;
  179.  
  180.     if (m_aacCharTable != NULL)
  181.     {
  182.         for (i = 0; i < m_uCharTableSize; i++)
  183.             delete[] m_aacCharTable[i];
  184.  
  185.         delete[] m_aacCharTable;
  186.     }
  187.  
  188.     if (m_aafFloatTable != NULL)
  189.     {
  190.         for (i = 0; i < m_uFloatTableSize; i++)
  191.             delete[] m_aafFloatTable[i];
  192.  
  193.         delete[] m_aafFloatTable;
  194.     }
  195.  
  196.     return S_OK;
  197. }
  198.  
  199.  
  200.  
  201. inline HRESULT CArrayTable::Add(ArrayType_t ArrayType, void* avArray) 
  202. {
  203.  
  204.     switch(ArrayType)
  205.     {
  206.     case CHAR_ARRAY:
  207.     case STRING:
  208.         if (m_uCharTableSize >= m_uCharTableMax) 
  209.         {    // double the array size
  210.  
  211.             char** aacCharTable = m_aacCharTable;
  212.  
  213.             m_uCharTableMax *= 2;
  214.  
  215.             m_aacCharTable = NULL;
  216.             m_aacCharTable = new char*[m_uCharTableMax];
  217.             if (m_aacCharTable == NULL) 
  218.             {
  219.                 m_aacCharTable = aacCharTable;
  220.                 return E_OUTOFMEMORY;
  221.             }
  222.  
  223.             memcpy(m_aacCharTable, aacCharTable, m_uCharTableSize * sizeof(char*));
  224.  
  225.             delete[] aacCharTable;
  226.         }
  227.  
  228.         m_aacCharTable[m_uCharTableSize++] = (char*)avArray;
  229.         break;
  230.     case FLOAT_ARRAY:
  231.         if (m_uFloatTableSize >= m_uFloatTableMax) 
  232.         {    // double the array size
  233.  
  234.             float** aafFloatTable = m_aafFloatTable;
  235.  
  236.             m_uFloatTableMax *= 2;
  237.  
  238.             m_aafFloatTable = NULL;
  239.             m_aafFloatTable = new float*[m_uFloatTableMax];
  240.             if (m_aafFloatTable == NULL) 
  241.             {
  242.                 m_aafFloatTable = aafFloatTable;
  243.                 return E_OUTOFMEMORY;
  244.             }
  245.  
  246.             memcpy(m_aafFloatTable, aafFloatTable, m_uFloatTableSize * sizeof(float*));
  247.  
  248.             delete[] aafFloatTable;
  249.         }
  250.  
  251.         m_aafFloatTable[m_uFloatTableSize++] = (float*)avArray;
  252.         break;
  253.     default:
  254.         return E_FAIL;    // array type not found
  255.     }
  256.  
  257.     return S_OK;
  258. }
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283. #endif